package com.jy.wms.common.quartz;

import com.jy.wms.service.WmsGoodsAlarmService;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 货品预警定时任务
 * @author liyi
 */
public class wmsGoodsAlarmScheduledJob implements Job {

    private  WmsGoodsAlarmService wmsGoodsAlarmService;
    private static Logger log = LoggerFactory.getLogger(wmsGoodsAlarmScheduledJob.class);
    private SimpleDateFormat dateFormat() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        try {
            log.info("货品预警定时任_货品有效期预警启动时间：" + dateFormat().format(new Date()));
            JobDataMap dataMap = context.getJobDetail().getJobDataMap();
            wmsGoodsAlarmService = (WmsGoodsAlarmService)dataMap.get("wmsGoodsAlarmService");
            Integer count =  wmsGoodsAlarmService.baseInsertQuartz();
            log.info("货品有效期预警加入：" + count + "条信息");
            log.info("货品预警定时任_货品有效期预警启动时间：" + dateFormat().format(new Date()));
            count = wmsGoodsAlarmService.baseInsertGoodsQuartz();
            log.info("货品有效期预警加入：" + count + "条信息");

            log.info("货品预警定时任_货品库存预警启动时间：" + dateFormat().format(new Date()));
            Integer countKc =  wmsGoodsAlarmService.baseInsertQuartzKc();
            log.info("货品库存预警加入：" + countKc + "条信息");
            log.info("货品预警定时任_货品库存预警启动时间：" + dateFormat().format(new Date()));
            countKc = wmsGoodsAlarmService.baseInsertGoodsQuartz();
            log.info("货品库存预警加入：" + countKc + "条信息");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("货品库存预警定时任异常");
            log.error(e.getMessage());
        }
    }
}